import unittest

from server.framework.core.logger import logger
from server.framework.core.settings import settings
from server.framework.utils.prometheus_manager import PrometheusManager


class PrometheusManagerTest(unittest.TestCase):
    def setUp(self) -> None:
        super().setUp()
        settings.prometheus_address = 'http://19.30.100.11:9090'
        self.prometheus_manager = PrometheusManager()
        self.node_lists = ['19.30.100.11']
        self.query_type = self.prometheus_manager.query_type

    def test_query(self):
        exp = 'sum(node_memory_MemTotal_bytes - node_memory_MemAvailable_bytes)'
        res = self.prometheus_manager.query(exp)
        logger.info(res)

    def test_metric_query(self):
        for name in self.query_type:
            rs = self.prometheus_manager.query_metrics(None, self.query_type[name])
            logger.info(f'{name}:{rs}')


if __name__ == '__main__':
    unittest.main()
